<template>
  <div class="show_budget">
    <span class="pull-right">
      <router-link class="btn btn btn-primary" v-bind:to="'Edit/'+budget.id">
        编辑
      </router-link>
      <button class="btn btn-danger delete" v-on:click="deletebudget(budget.id)">删除</button>
      <router-link to="/budget/Center" class="btn btn-warning">返回</router-link>
    </span>
    <div class="single_budget">
      <ul class="list-group">
        <li class="list-group-item budget_type">账单{{budget.type}}</li>
        <li class="list-group-item">时间：<span class=" glyphicon glyphicon-time "></span> {{budget.time}}</li>
        <li class="list-group-item">金额：¥{{budget.amount}}</li>
        <li class="list-group-item">备注：{{budget.remark}}</li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  name: 'SingleBudget',
  data () {
    return {
      budget: {}
    }
  },
  methods: {
    fetchbudgets (budgetid) {
      this.$http.get('http://localhost:3000/budget/' + budgetid)
        .then(function (data) {
          console.log(data)
          this.budget = data.body
        })
    },
    deletebudget (id) {
      // console.log(id);
      this.$http.delete('http://localhost:3000/budget/' + id)
        .then((response) => {
          this.$router.push({path: '/Budget/Center', query: {alert: '账单删除成功!'}})
        })
    }
  },
  created () {
    this.fetchbudgets(this.$route.params.id)
  }
}
</script>

<style scoped>
  .single_budget{
    max-width: 960px;
    padding: 50px 20px 30px 20px;
    margin: 30% auto;
  }
  .list-group-item{
    border: 1px solid #66cdaa;
    background: white;
    font-size: 16px;
  }
  /*.show_budget{*/
  /*  background: rgb(208,233,198);*/
  /*}*/
  h1{
    text-transform: uppercase;
    text-align: center;
    padding: 10px 0;
    font-weight: bolder;
    color: #66cdaa;
  }
  .budget_type{
    text-align: center;
    font-size: 18px;
    color: black;
  }

</style>
